package com.zhouheng.common.jackson;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.text.SimpleDateFormat;

public class StandardMapper extends ObjectMapper {
    static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss";

    private static StandardMapper instance = new StandardMapper();

    private StandardMapper() {
        this.setSerializationInclusion(JsonInclude.Include.ALWAYS);
        this.setDateFormat(new SimpleDateFormat(STANDARD_FORMAT));
        this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        this.registerModule(new JavaTimeModule());
    }

    public static StandardMapper getInstance() {
        return instance;
    }
}
